package com.zjf.carpark.controller;


import com.zjf.carpark.entities.Menu;
import com.zjf.carpark.service.impl.MenuServiceImpl;
import com.zjf.carpark.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

import static com.zjf.carpark.utils.CodeAndMessage.*;


/**
 * 页面跳转控制器
 */
@CrossOrigin
@Controller
@RequestMapping("desk")
public class DeskController {
    @Autowired
    private MenuServiceImpl menuService;

    /**
     * 登录
     *
     * @return
     */
    @RequestMapping(value = "login")
    public String login1() {
        return "login1";
    }

    /**
     * 控制台
     *
     * @return
     */
    @RequestMapping(value = "console")
    public String console() {
        return "console";
    }

    /**
     * 跳转到主页面
     *
     * @return
     */
    @RequestMapping(value = "main")
    public String tomain() {
        return "main";
    }

    /**
     * 添加权限
     *
     * @return
     */
    @RequestMapping(value = "addOwner")
    public String addRole() {
        return "addOwner";
    }

    /**
     * 管理用户信息
     *
     * @return
     */
    @RequestMapping(value = "editOwner")
    public String editRole() {
        return "editOwner";
    }

    /**
     * 添加用户
     *
     * @return
     */
    @RequestMapping(value = "addUser")
    public String addUser() {
        return "addUser";
    }

    /**
     * 管理用户信息
     *
     * @return
     */
    @RequestMapping(value = "editUser")
    public String editUser() {
        return "editUser";
    }

    /**
     * 管理公告信息
     *
     * @return
     */
    @RequestMapping(value = "editAnnounce")
    public String editAnnounce() {
        return "editAnnounce";
    }

    /**
     * 新增公告
     *
     * @return
     */
    @RequestMapping(value = "addAnnounce")
    public String addAnnounce() {
        return "addAnnounce";
    }

    /**
     * 公告详情
     *
     * @return
     */
    @RequestMapping(value = "announceDetails")
    public String announceDetails() {
        return "announceDetails";
    }

    /**
     * 添加车位信息
     *
     * @return
     */
    @RequestMapping(value = "addCarPark")
    public String addCarPark() {
        return "addCarPark";
    }

    /**
     * 添加IC卡信息
     *
     * @return
     */
    @RequestMapping(value = "editICcard")
    public String editICcard() {
        return "editICcard";
    }

    /**
     * 出入场设置
     *
     * @return
     */
    @RequestMapping(value = "fixedowner-inAndOut")
    public String fixedownerinAndOut() {
        return "fixedowner-inAndOut";
    }

    /**
     * 添加IC卡信息
     *
     * @return
     */
    @RequestMapping(value = "addICcard")
    public String addICcard() {
        return "addICcard";
    }

    /**
     * 管理私人车位信息
     *
     * @return
     */
    @RequestMapping(value = "editCarPark")
    public String editCarPark() {
        return "editCarPark";
    }

    /**
     * 管理普通车位信息
     *
     * @return
     */
    @RequestMapping(value = "editCarPark-normal")
    public String editCarParkNormal() {
        return "editCarPark-normal";
    }

    /**
     * 停车信息管理
     *
     * @return
     */
    @RequestMapping(value = "fixedowner-parkmsg")
    public String fixedownerparkmsg() {
        return "fixedowner-parkmsg";
    }

    /**
     * 临时车辆停车管理-车主入场信息
     *
     * @return
     */
    @RequestMapping(value = "linShiCar")
    public String linShiCar() {
        return "linShiCar";
    }

    /**
     * 临时车辆停车管理-车主出场信息
     *
     * @return
     */
    @RequestMapping(value = "linShiOut")
    public String linShiOut() {
        return "linShiOut";
    }

    /**
     * 系统日志
     *
     * @return
     */
    @RequestMapping(value = "log")
    public String log() {
        return "log";
    }

    /**
     * 数据图表
     *
     * @return
     */
    @RequestMapping(value = "chart")
    public String chart() {
        return "lineChart";
    }

    /**
     * 基本资料
     *
     * @return
     */
    @RequestMapping(value = "jibenziliao")
    public String jibenziliao() {
        return "jibenziliao";
    }

    /**
     * 用户详情弹窗
     *
     * @return
     */
    @RequestMapping(value = "editUser-eject")
    public String eject() {
        return "editUser-eject";
    }

    /**
     * 用户编辑自己的信息
     */
    @RequestMapping(value = "userUpdate")
    public String userUpdate() {
        return "userUpdate";
    }

    /**
     * 入场扫描
     *
     * @return
     */
    @RequestMapping(value = "in")
    public String in() {
        return "in";
    }

    /**
     * 出场扫描
     *
     * @return
     */
    @RequestMapping(value = "out")
    public String out() {
        return "out";
    }

    /**
     * 柱状图
     *
     * @return
     */
    @RequestMapping("barChart")
    public String barChart() {
        return "barChart";
    }

    /**
     * 折线图
     *
     * @return
     */
    @RequestMapping("lineChart")
    public String lineChart() {
        return "lineChart";
    }

    /**
     * 支付成功
     *
     * @return
     */
    @RequestMapping("paySuccess")
    public String paySuccess() {
        return "paySuccess";
    }

    /**
     * 支付失败
     *
     * @return
     */
    @RequestMapping("payfailed")
    public String payfailed() {
        return "payfailed";
    }

    /**
     * 临时停车详情页面
     *
     * @return
     */
    @RequestMapping("LSDetails")
    public String LSDetails() {
        return "LSDetails";
    }

    /**
     * 私人用户详情
     *
     * @return
     */
    @RequestMapping("editOwner-eject")
    public String editOwner() {
        return "editOwner-eject";
    }

    /**
     * 移动端
     *
     * @return
     */
    @RequestMapping("app")
    public String app() {
        return "app";
    }

    /**
     * 移动端登录
     *
     * @return
     */
    @RequestMapping("ownerLogin")
    public String login() {
        return "login";
    }

    /**
     * 车位图
     */
    @RequestMapping("parkPlace")
    public String parkPlace() {
        return "parkPlace";
    }

    /**
     * @return
     */
    @RequestMapping("appEject")
    public String appEject() {
        return "app-eject";
    }

    /**
     * 前台公告
     *
     * @return
     */
    @RequestMapping("announcement")
    public String announcment() {
        return "announcement";
    }

    /**
     * 前台公告
     *
     * @return
     */
    @RequestMapping("advise")
    public String advise() {
        return "advise";
    }

    /**
     * 公告详情
     *
     * @return
     */
    @RequestMapping("oneAnnouncement")
    public String oneAnnouncement() {
        return "oneAnnounce";
    }

    /**
     * 欢迎
     *
     * @return
     */
    @RequestMapping("welcome")
    public String welcome() {
        return "welcome";
    }

    /**
     * 广告
     *
     * @return
     */
    @RequestMapping("adver")
    public String adver() {
        return "adver";
    }

    /**
     * 得到登录用户的菜单
     *
     * @param data
     * @return
     */
    @RequestMapping("getMenu")
    @ResponseBody
    public ResponseData getMenu(@RequestBody Map<String, Integer> data) {
        ResponseData responseData;
        Integer roleId = data.get("roleId");
        List<Menu> menus = menuService.selectMenusByRoleId(roleId);
        if (menus.size() != 0) {
            responseData = new ResponseData(CODE200, SUCCESS);
            responseData.putDataValue("menus", menus);
        } else {
            responseData = new ResponseData(CODE0, ERROR);
        }
        return responseData;
    }
}
